const db = require('../../database/index');
const writeLogs = require('./writeLogs');

module.exports = (req, res) => {
    const {newFriendList} = req.body;
    const username = req.auth.username;
    const sql = 'update users set friends = ? where username = ?';
    db.query(sql, [newFriendList, username], (err, data)=> {
        if (err) return res.cc(err)
        if (data.affectedRows === 0) return res.cc('好友列表更新失败！')
        writeLogs('updateFriends', {
            username,
            friends: newFriendList,
        })
        res.cc('删除成功', 0);
    })
}